package org.jbelis.yodaquotes.server;

import java.io.Writer;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.json.JSONException;
import org.json.JSONWriter;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Quote {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String text;

    @Persistent
    private Integer episode;

    @Persistent
    private String context;

    public Quote(String quote, Integer episode, String context) {
        this.text = quote;
        this.episode = episode;
        this.context = context;
    }

    public Long getId() {
        return id;
    }

    public String getText() {
        return text;
    } 

    public String getContext() {
        return context;
    } 

    public Integer getEpisode() {
        return episode;
    } 
    
    public void write(Writer writer) throws JSONException {
		JSONWriter json = new JSONWriter(writer);

		json.object();
		json.key("text");
		json.value(getText());
		json.key("episode");
		json.value(getEpisode());
		json.endObject();

    }

}

